
<template>
  <div>
    <!-- FIXME:条件搜托条 -->
    <div class="topSearch">
      <div class="leftBox" style="max-width:100%;">
        <div class="searchbox">
          <em>缴费方案名称：</em>
          <el-select
            v-model="searchBox.projectId"
            @change="changPJ"
            placeholder="请选择"
            size="small"
            style="width:150px"
          >
            <el-option
              v-for="item in projectList"
              :key="item.projectId"
              :label="item.projectName"
              :value="item.projectId"
            ></el-option>
          </el-select>
        </div>
        <div class="searchbox">
          <em>学生姓名或身份证号：</em>
          <el-input
            v-model="searchBox.peoNameOrIdcard"
            size="small"
            style="width:200px"
            placeholder="请输入学生姓名或身份证号"
          ></el-input>
        </div>
        <div class="searchbox">
          <em>缴费类型：</em>
          <el-select
            v-model="searchBox.category"
            placeholder="请选择"
            size="small"
            style="width:100px"
          >
            <el-option key label="全部" value></el-option>
            <el-option
              v-for="item in categoryList"
              :key="item.category"
              :label="item.categoryName"
              :value="item.category"
            ></el-option>
          </el-select>
        </div>
        <br>
        <div class="searchbox">
          <em>校区：</em>
          <el-select
            v-model="searchBox.schoolId"
            @change="changSC"
            placeholder="请选择"
            size="small"
            style="width:100px"
          >
            <el-option key label="全部" value></el-option>
            <el-option
              v-for="item in schoolList"
              :key="item.schoolId"
              :label="item.schoolName"
              :value="item.schoolId"
            ></el-option>
          </el-select>
        </div>

        <div class="searchbox">
          <em>就读年级：</em>
          <el-select v-model="searchBox.gradeId" @change="gradeChange" placeholder="请选择" size="small" style="width:100px">
            <el-option key label="全部" value></el-option>
            <el-option
              v-for="item in gradeList"
              :key="item.gradeId"
              :label="item.gradeName"
              :value="item.gradeId"
            ></el-option>
          </el-select>
        </div>
        <div class="searchbox">
          <em>班级：</em>
          <el-select v-model="searchBox.classId" placeholder="请选择" :disabled="searchBox.studentSource=='Sign'" size="small" style="width:100px">
            <el-option key label="全部" value></el-option>
            <el-option
              v-for="item in classList"
              :key="item.classId"
              :label="item.className"
              :value="item.classId"
            ></el-option>
          </el-select>
        </div>

        <div class="searchbox">
          <em>是否减免：</em>
          <el-radio-group v-model="searchBox.isTuition">
            <el-radio label="">全部</el-radio>
            <el-radio label="Y">是</el-radio>
            <el-radio label="N">否</el-radio>
          </el-radio-group>
        </div>
        <div class="searchbox">
          <el-button type="primary" @click="getReductionList" size="mini">查询</el-button>
          <!-- <el-button type="primary" @click="dialogFormVisible=!dialogFormVisible" size="mini">新增减免</el-button> -->
        </div>
      </div>
      <div class="clear"></div>
    </div>

    <div class="contentBox" style="height:87%">
      <el-table :data="reductionList" :header-cell-style="headClass" border stripe style="width: 100%" height="90%">
        <el-table-column prop="projectName" label="缴费方案名称" width="200"></el-table-column>
        <el-table-column label="方案状态" width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.projectState=='Draft'" style="color:#6ac0e0;">草稿</span>
            <span v-else-if="scope.row.projectState=='UnPublished'" style="color:#6ac0e0;">未发布</span>
            <span v-else-if="scope.row.projectState=='Published'" style="color:#54b32d;">已发布</span>
            <span v-else style="color:#F30;">停用</span>
          </template>
        </el-table-column>
        <el-table-column prop="paymentCategoryName" label="缴费类型" width="120"></el-table-column>
        <el-table-column prop="schoolName" label="所在校区" width="200"></el-table-column>
        <el-table-column prop="gradeName" label="就读年级"></el-table-column>
        <el-table-column label="班级" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.className==null||scope.row.className==undefined||scope.row.className==''">未设置班级</span>
            <span v-else>{{scope.row.className}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="studentName" label="姓名" width="120">
          <!-- <template slot-scope="scope">
              <strong style="color:#ff6910; font-size:16px;">{{scope.row.studentName}}</strong>
            </template> -->
        </el-table-column>
        <el-table-column prop="identityCardNumber" label="身份证号" width="200"></el-table-column>
        <el-table-column label="是否减免" width="120">
          <template slot-scope="scope">
            <!-- <span v-if="parseFloat(scope.row.tuitionMoney).toFixed(2)*1000!=0&&scope.row.tuitionMoney!=null&&scope.row.tuitionMoney!=undefined&&scope.row.tuitionMoney!=''">已减免</span> -->
            <span v-if="scope.row.isTuition=='N'">未减免</span>
            <span v-else>已减免</span>
          </template>
        </el-table-column>

        <el-table-column label="应缴金额">
          <template slot-scope="scope">
            <span
              v-if="scope.row.payableMoney==''||scope.row.payableMoney==null||scope.row.payableMoney==undefined"
            >0.00</span>
            <span :class="{fuFont:parseFloat(scope.row.payableMoney?scope.row.payableMoney:0).toFixed(2)*1000<0}" v-else>{{scope.row.payableMoney|moneyStyle}}</span>
          </template>
        </el-table-column>
        <el-table-column label="实缴金额">
          <template slot-scope="scope">
            <span
              v-if="scope.row.paidMoney==''||scope.row.paidMoney==null||scope.row.paidMoney==undefined"
            >0.00</span>
            <span :class="{fuFont:parseFloat(scope.row.paidMoney?scope.row.paidMoney:0).toFixed(2)*1000<0}" v-else>{{scope.row.paidMoney|moneyStyle}}</span>
          </template>
        </el-table-column>
        <el-table-column label="减免总金额" width="120">
          <template slot-scope="scope">
            <span style="color:#e8851e;" v-if="scope.row.tuitionMoney==''||scope.row.tuitionMoney==null||scope.row.tuitionMoney==undefined"
            >0.00</span>
            <span style="color:#e8851e;" :class="{fuFont:parseFloat(scope.row.tuitionMoney?scope.row.tuitionMoney:0).toFixed(2)*1000<0}" v-else>{{scope.row.tuitionMoney|moneyStyle}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="owedMoney" label="欠缴金额">
          <template slot-scope="scope">
            <!-- <span>{{scope.row.payableMoney-scope.row.paidMoney-scope.row.tuitionMoney}}</span> -->
            <span>{{qianjiao(scope.row)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="110">
          <template slot-scope="scope">
            <!-- :disabled="!(parseFloat(scope.row.tuitionMoney?scope.row.tuitionMoney:0).toFixed(2)*1000==0)"  -->
            <el-button @click="addReduction(scope.row)" type="primary" size="mini">设置减免</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="paging">
        <el-pagination
          background
          layout="total, prev, pager, next"
          @current-change="handleCurrentChange"
          :current-page.sync="pageIndex"
          :total="pageAll"
        ></el-pagination>
      </div>
    </div>

    <!-- 弹层内容 -->
    <el-dialog title="增加减免" :visible.sync="dialogFormVisible" width="70%">
      <div class="layerMaxHeight">
        <div class="layerBox">
          <div class="baseMessage">
            <ul>
              <li>
                <em>姓名：</em><strong style="color:#ff6a00; font-size:16px;">{{baseMes.studentName}}</strong>
              </li>
              <li>
                <em>年级：</em>
                {{baseMes.gradeName}}
              </li>
              <li>
                <em>班级：</em>
                <span v-if="baseMes.className==''||baseMes.className==null||baseMes.className==undefined">暂未设置班级</span>
                <span v-else>{{baseMes.className}}</span>
              </li>
              <li>
                <em>缴费类型：</em>
                {{baseMes.paymentCategoryName}}
              </li>
              <li v-if="baseMes.studentSource!='Student'&&baseMes.isShiftIn=='0'">
                <em>中考裸分：</em>
                {{baseMes.totalScre}}
              </li>
              <li v-if="baseMes.studentSource!='Student'&&baseMes.isShiftIn=='0'">
                <em>中考加分：</em>
                {{baseMes.bonusScores}}
              </li>
              <li v-if="baseMes.studentSource!='Student'&&baseMes.isShiftIn=='0'">
                <em>预报名加分：</em>
                {{baseMes.preBonusScore}}
              </li>
              <li>
                <em>欠缴金额：</em>
                {{baseMes.qianjiao}}
              </li>
            </ul>
          </div>

          <div class="tableStyleW">
            <table
              class="tableStyle"
              style="margin:0 auto"
              width="auto"
              cellpadding="0"
              cellspacing="0"
            >
              <thead>
                <tr>
                  <th rowspan="2" width="160">类型</th>
                  <th :colspan="expenseDetails.length">各项目减免费用明细</th>
                </tr>
                <tr>
                  <th v-for="(a,index1) in expenseDetails" :key="index1">{{a.itemName}}</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>应收金额（招办填写）</td>
                  <td v-for="(b,index2) in expenseDetails" :key="index2">{{b.money}}</td>
                </tr>
                <tr>
                  <td>减免录入</td>
                  <td v-for="(c,index3) in expenseDetails" :key="index3">
                    <el-input-number
                      v-model="c.youhui"
                      :precision="2"
                      :step="0.01"
                      :class="{ 'fu' :parseFloat(c.youhui?c.youhui:0).toFixed(2)*1000<0 }"
                      @change="setYouhui(index3)"
                      style="width:120px;"
                      :controls="false"
                    ></el-input-number>
                  </td>
                </tr>
                <tr>
                  <td>合计</td>
                  <td v-for="(d,index4) in expenseDetails" :key="index4">{{d.heji|kexuejishu}}</td>
                </tr>
              </tbody>
            </table>
          </div>

          <el-form ref="form" :model="form" :rules="rules" size="small" label-width="140px">
            <el-form-item label="减免审批单">
              <!-- <em style="float:left; margin:3px 0px 0px -95px; color:red">*</em> -->
              <el-upload
                class="upload-demo"
                action="/common/file/upload"
                :show-file-list="false"
                :on-success="(a,b)=>handleAvatarSuccessJMSP(a,b)"
                :data="{fileType:'Tuition',flag:form.fileId==''?'ADD':'EDIT',fileId:form.fileId==''?'':form.fileId,studentId:form.studentId}"
                style="width:250px"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">附件可上传JPG，PNG格式</div>
              </el-upload>
              <div class="fileList">
                <ul>
                  <li v-for="(f,index) in fileList" :key="index">
                    <em>
                      <i class="el-icon-s-management"></i>
                    </em>
                    <div class="set">
                      <el-tooltip class="item" effect="dark" content="预览" placement="top">
                        <!-- <a class="down" @click="downlade(f.url)">
                          <i class="el-icon-view"></i>
                        </a> -->
                        <el-button @click="downlade(f.url)" type="primary" size="mini" icon="el-icon-view" circle></el-button>
                      </el-tooltip>
                      <el-tooltip class="item" effect="dark" content="删除" placement="top">
                        <!-- <a class="drop" @click="dropfiel(index)">
                          <i class="el-icon-close"></i>
                        </a> -->
                        <el-button :disabled="!f.drop" @click="dropfiel(index)" type="danger" size="mini" icon="el-icon-close" circle></el-button>
                      </el-tooltip>
                    </div>
                    <div class="mes">
                      <p>{{f.name}}</p>
                    </div>
                  </li>
                </ul>
              </div>
            </el-form-item>
            <el-form-item label="成绩单" v-if="baseMes.studentSource!='Student'">
              <div v-if="chengjidanList.length>0">
               <el-image v-for="(f,index1) in chengjidanList" :key="index1" @click="showImgBig(imgUrlLeft+f)" style="width: 100px; height: 100px" :src="imgUrlLeft+f"></el-image>
               </div>
               <el-tag v-else type="info">暂无成绩单</el-tag>
            </el-form-item>
            <el-form-item label="报名系统减免凭据" v-if="baseMes.studentSource!='Student'">

              <el-image v-for="(j,index2) in jianmianpingjuList" :key="index2" @click="showImgBig(imgUrlLeft+j)" style="width: 100px; height: 100px" :src="imgUrlLeft+j"></el-image>
            </el-form-item>

            <!-- <el-form-item label="董事长减免意见">
              <el-upload
                class="avatar-uploader"
                action="/common/file/upload"
                :show-file-list="false"
                :on-success="(a,b)=>handleAvatarSuccess(a,b)"
                :data="{fileType:'Tuition',flag:form.fileId==''?'ADD':'EDIT',fileId:form.fileId==''?'':form.fileId,studentId:form.studentId}"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="form.file" :src="$store.state.userModule.phurl+form.file" class="avatar" />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item> -->
            <el-form-item label="是否寄宿">
              <el-tag v-if="baseMes.isResidence=='1'||removeSpaces(baseMes.isResidence)=='是'">是</el-tag>
              <el-tag v-else type="info">否</el-tag>
            </el-form-item>
            <el-form-item label="减免说明">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                maxlength="200"
                show-word-limit
                style="width:500px;"
                :rows="4"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <!-- FIXME:保存增加减免 -->
        <el-button type="primary" @click="saveReduction">确 定</el-button>
      </div>
    </el-dialog>

    <el-image-viewer  v-if="showViewer" :on-close="closeViewer" :url-list="[url]" style="z-index:20000" />

  </div>
</template>

<script>
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'

export default {
  name: "receivable",
  components: { ElImageViewer },
  // TODO:数据内容
  data() {
    return {
      pageIndex: 1,
      pageAll: 0,
      dialogFormVisible: false,
      showViewer:false,
      url:'',
      chengjidanList:[],
      jianmianpingjuList:[],
      searchBox: {
        projectId: "",
        studentSource: "",
        nameorcard: "",
        peoNameOrIdcard: "",
        Idcard: "",
        schoolId: "",
        gradeId: "",
        classId: "",
        category: "",
        jianmian: 0,
        isTuition:"",
      },
      gradeList: [],
      projectList: [],
      schoolList: [],
      classList: [],
      categoryList: [],
      reductionList: [],
      flag: "",
      baseMes: {},
      expenseDetails: [],
      form: {
        projectId: "",
        studentId: "",
        schoolId: "",
        idCard: "",
        fileId: "",
        fileId1: "",
        fileId2: "",
        file: "",
        file1: "",
        file2: "",
        remark: "",
        tuition: "",
        other: "",
        explain: ""
      },
      fileList: [],
      fileList1: [],
      imgUrlLeft:'',
      rules:{
        fileList:[{ type: 'array', required: true, message: '请上传退费审批单', trigger: 'change' }],
      }
    }
  },
  // 监视
  watch:{
    "searchBox.projectId":function(v){
      if(v){
        this.getReductionList();
      }
    },
    "searchBox.category":function(v){
      if(v){
        this.getReductionList();
      }
    },
    "searchBox.schoolId":function(v){
      if(v){
        this.getReductionList();
      }
    },
    "searchBox.gradeId":function(v){
      if(v){
        this.getReductionList();
      }
    },
    "searchBox.classId":function(v){
      if(v){
        this.getReductionList();
      }
    }

  },
  filters: {
    moneyStyle(val) {
      if(!val)return '--';
      var nm = 0;
      nm = parseFloat(val).toFixed(2);
      return nm;
    },
    gradeName(val) {
      switch (val) {
        case "7":
          return "初一";
          break;
        case "8":
          return "初二";
          break;
        case "9":
          return "初三";
          break;
      }
    },
    kexuejishu(val){
      if(/\d+\.?\d*e[\+\-]*\d+/i.test(val)) {    //正则匹配科学计数法的数字
          var zero = '0',                                    //
            parts = String(val).toLowerCase().split('e'), //拆分成系数和指数
            e = parts.pop(),//存储指数
            l = Math.abs(e), //取绝对值，l-1就是0的个数
            sign = e/l,          //判断正负
            coeff_array = parts[0].split('.');   //将系数按照小数点拆分
          if(sign === -1) {           //如果是小数
            val = zero + '.' + new Array(l).join(zero) + coeff_array.join('');   //拼接字符串，如果是小数，拼接0和小数点
          } else {
            var dec = coeff_array[1];
            if(dec) l = l - dec.length;  //如果是整数，将整数除第一位之外的非零数字计入位数，相应的减少0的个数
            val = coeff_array.join('') + new Array(l+1).join(zero);    //拼接字符串，如果是整数，不需要拼接小数点
          }
        }

        return val;
    }
  },
  mounted() {
    this.getProject("project");
  },
  methods: {
    // 字符串去空格
    removeSpaces(mes){
      if(!mes) return "0";
      return mes.replace(/\s*/g,"");
    },
    // 头部样式
    headClass:function(){
      return 'text-align: center;'
    },
    // 获取项目
    getProject: function(type) {
      this.$api.trainingReduction.Getcondition(type, "", "", "").then(res => {
        //console.log("获取缴费项目", res);
        this.projectList = res.data.result.projectList;
        this.searchBox.projectId = res.data.result.projectList[0].projectId;
        this.searchBox.studentSource = res.data.result.projectList[0].studentSource;
        this.getSchool("school");
      });
    },
    // 获取学校
    getSchool: function(type) {
      this.$api.trainingReduction
        .Getcondition(
          type,
          this.searchBox.projectId,
          this.searchBox.schoolId,
          this.searchBox.gradeId
        )
        .then(res => {
          //console.log("获取学校", res);
          this.schoolList = res.data.result.schoolList;
          this.searchBox.schoolId = res.data.result.schoolList[0].schoolId;
          this.getcondition("gradeAndCategory");
        });
    },
    // 获取搜索条件
    getcondition: function(type) {
      this.$api.trainingReduction
        .Getcondition(
          type,
          this.searchBox.projectId,
          this.searchBox.schoolId,
          this.searchBox.gradeId
        )
        .then(res => {
          //console.log("获取搜索条件", res);
          this.categoryList = res.data.result.categoryList;
          this.gradeList = res.data.result.gradeList;
          this.getReductionList();
          // this.searchBox.gradeId = res.data.result.gradeList[0].gradeId;
          // this.getClass("class");
        });
    },
    // 年级修改
    gradeChange:function(){
      this.searchBox.classId = "";
      this.getClass("class");
    },
    // 获取班级
    getClass: function(type) {
      this.$api.trainingReduction
        .Getcondition(
          type,
          this.searchBox.projectId,
          this.searchBox.schoolId,
          this.searchBox.gradeId
        )
        .then(res => {
          //console.log("获取班级列表", res);
          this.classList = res.data.result.classList;
          // this.getReductionList();
        });
    },
    // 欠缴
    qianjiao: function(obg) {
      var numq = 0;
      numq =
        (parseFloat(obg.payableMoney == null ? 0 : obg.payableMoney) * 1000 -
          parseFloat(obg.paidMoney == null ? 0 : obg.paidMoney) * 1000 -
          parseFloat(obg.tuitionMoney == null ? 0 : obg.tuitionMoney) * 1000) /
        1000;
      return parseFloat(numq).toFixed(2);
    },
    heji: function(obg) {
      var heji = 0;
      heji =
        (parseFloat(obg.shishou == null ? 0 : obg.shishou) * 1000 -
          parseFloat(obg.youhui == null ? 0 : obg.youhui) * 1000) /
        1000;
      return parseFloat(heji).toFixed(2);
    },
    // 缴费方案改变
    changPJ: function(event) {
      for (var a = 0, lenn = this.projectList.length; a < lenn; a++) {
        if (this.projectList[a].projectId == event) {
          this.searchBox.studentSource = this.projectList[a].studentSource;
        }
      }
    },
    // 学校改变
    changSC:function(event){
      this.searchBox.gradeId = "";
      this.getcondition("gradeAndCategory");
    },
    // 年级改变
    changGD:function(event){
      this.searchBox.classId = "";
      this.getClass("class");
    },

    // 获取减免列表
    getReductionList: function() {
      this.$api.trainingReduction
        .GetReductionList(
          this.searchBox.projectId,
          this.searchBox.studentSource,
          this.searchBox.schoolId,
          this.searchBox.gradeId,
          this.searchBox.category,
          this.searchBox.peoNameOrIdcard,
          this.searchBox.classId,
          this.searchBox.isTuition,
          this.pageIndex
        )
        .then(res => {
          //console.log("获取减免列表", res);
          this.reductionList = res.data.result.list;
          this.pageIndex = res.data.result.page;
          this.pageAll = res.data.result.total;
          this.reductionList.forEach(e=>{
            if(e.isResidence=="0"||e.isResidence.replace(/\s*/g,"")=="否"){
              e.payableMoney = (parseFloat(e.payableMoney).toFixed(2)*1000-parseFloat(e.boarderMoney).toFixed(2)*1000)/1000
            }
          })
        });
    },
    handlePreview: function() {},
    handleRemove: function() {},
    beforeRemove: function() {},
    handleExceed: function() {},
    // 获取名字
    getName:function(obj){
      var index = obj.lastIndexOf("\/");
      obj=obj.substring(index+1,obj.length)
      return obj;
    },
    // 减免审批成功
    handleAvatarSuccessJMSP: function(res, file) {
      console.log(res);
      var fileSuccessObg = {
        id:res.result.id,
        name:this.getName(res.result.url),
        url: this.$store.state.userModule.phurl + res.result.url,
        drop:true
      };
      this.fileList.push(fileSuccessObg);
      this.fileList1.push(fileSuccessObg);
    },
    // 上传成功
    handleAvatarSuccess(res, file) {
      this.form.fileId = res.result.id;
      this.form.file = res.result.url;
    },
    // 上传文件之前
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    // 删除附件
    dropfiel:function(suoyin){
      this.fileList.splice(suoyin,1);
    },
    // 增加减免
    addReduction: function(obg) {
      // console.log(obg)
      this.form.studentId = obg.studentId;
      this.form.projectId = obg.projectId;
      this.form.idCard = obg.identityCardNumber;
      this.form.schoolId = obg.schoolId;
      this.fileList = [];
      this.fileList1 = [];
      this.chengjidanList = [];
      var getObg = {};
      this.$api.trainingReduction
        .GetReductionInitializedData(
          obg.projectId,
          obg.studentId,
          obg.studentSource
        )
        .then(res => {
          //console.log("获取减免初始换数据", res);
          this.imgUrlLeft = res.data.result.signUrl;
          if(res.data.result.reportImg){
          // this.form.file1 = res.data.result.reportImg.replace(/,/g,'');
            var arr1 = res.data.result.reportImg.split(",");
            this.chengjidanList = arr1;
          }
          if(res.data.result.tuitionProof){
          // this.form.file2 = res.data.result.tuitionProof.replace(/,/g,'');
            var arr2 = res.data.result.tuitionProof.split(",");
            this.jianmianpingjuList = arr2;
          }

          if(res.data.result.fileTuition){
            res.data.result.fileTuition.forEach(event=>{
              var fileSuccessObg = {
                id:event.id,
                name:event.fileName,
                url: this.$store.state.userModule.phurl + event.fileUrl,
                drop:false,
              };

              this.fileList.push(fileSuccessObg);

            })

          }

          this.expenseDetails = res.data.result.itemInits;
          getObg.itemInits = res.data.result.itemInits;
          this.expenseDetails.forEach(e => {
            e.youhui = 0;
            e.heji = parseFloat(e.money).toFixed(2);
            if(res.data.result.itemViews){
              res.data.result.itemViews.forEach(ee=>{
                if(ee.itemId==e.itemId){
                  e.youhui = parseFloat(ee.money).toFixed(2);
                  e.heji = (parseFloat(e.money).toFixed(2)*1000-parseFloat(ee.money).toFixed(2)*1000)/1000;
                }
              })
            }
          });
          var newObg = Object.assign(obg, getObg);
          this.baseMes = JSON.parse(JSON.stringify(newObg));
          console.log(newObg);
          this.baseMes.qianjiao = this.qianjiao(obg);
          Object.assign(this.baseMes,res.data.result)

          this.dialogFormVisible = true;
        }).catch(error=>{
          console.log(error);
        });
    },
    // 设置优惠
    setYouhui: function(suoyin) {
      var that = this;
      if (
        parseFloat(that.expenseDetails[suoyin].youhui).toFixed(2) * 1000 >
        parseFloat(that.expenseDetails[suoyin].money).toFixed(2) * 1000
      ) {
        that.$message({
          message: "优惠价格不得大于应收金额",
          type: "warning"
        });
        that.expenseDetails[suoyin].youhui = parseFloat(0).toFixed(2);
      }
      var heshu = 0;
      heshu =
        (parseFloat(that.expenseDetails[suoyin].money).toFixed(2) * 1000 -
          parseFloat(that.expenseDetails[suoyin].youhui).toFixed(2) * 1000) /
        1000;
      that.expenseDetails[suoyin].heji = parseFloat(heshu).toFixed(2);
      that.expenseDetails = JSON.parse(JSON.stringify(that.expenseDetails));
    },
    // TODO:保存减免设置
    saveReduction: function() {
      var that = this;
      var youhuiNum = 0;
      for(var y=0,len = that.expenseDetails.length; y<len;y++){
        youhuiNum += parseFloat(that.expenseDetails[y].youhui).toFixed(2)*1000
      }
      if(youhuiNum==0){
        that.$message({
          message:'优惠金额未设置!',
          type:'warning'
        })
        return;
      }

      // if(that.fileList1.length==0&&that.baseMes.studentSource=="Sign"){
      //   that.$message({
      //     message:'请上传减免审批单!',
      //     type:'warning'
      //   })
      //   return;
      // }


      // that.$api.trainingReduction.VerificationReduction(that.form.projectId, that.form.studentId)
      //   .then(res => {
      //     //console.log("保存减免验证", res);
          // if (res.data.status == "SUCCESS") {
            // that.$message({
            //   message: "减免验证成功!正在保存",
            //   type: "success"
            // });

            var posFiles = "";
            for(var a=0,len = that.fileList.length;a<len;a++){
              posFiles +=that.fileList[a].id+",";
            }
            if(that.form.fileId){
              posFiles += that.form.fileId+",";
            }
            if(that.form.fileId1){
              posFiles += that.form.fileId1+",";
            }
            if(that.form.fileId2){
              posFiles += that.form.fileId2+",";
            }

            var posList = JSON.parse(JSON.stringify(that.expenseDetails))
            posList.forEach(e=>{
              e.money = e.youhui;
            })
            that.$api.trainingReduction
              .SaveReduction(
                that.form.projectId,
                that.form.studentId,
                that.form.idCard,
                that.form.remark,
                posFiles,
                posList
              )
              .then(res => {
                //console.log("保存增加减免返回", res);
                if (res.data.status == "SUCCESS") {
                  that.$message({
                    message: "保存增加减免成功!",
                    type: "success"
                  });
                  that.form.projectId = "";
                  that.form.studentId = "";
                  that.form.idCard = "";
                  that.form.fileId = "";
                  that.form.tuition = "";
                  that.form.other = "";
                  that.form.file = "";
                  that.dialogFormVisible = false;
                  that.getReductionList();
                } else {
                  that.$message.error(res.data.message);
                }
              });
          // } else {
          //   that.$message.error(res.data.message);
          // }
        // });
    },
    // 上传成功
    handleAvatarSuccess(res, file) {
      this.form.fileId = res.result.id;
      this.form.file = res.result.url;
    },
    // 上传文件之前
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    // 下载上传的附件
    downlade:function(url){
      window.open(url)
    },
    // 分页页面切换
    handleCurrentChange: function(val) {
      this.pageIndex = val;
      this.getReductionList();
    },
    // 显示大图
    showImgBig:function(u){
      this.showViewer = true
      this.url = u
    },
    // 关闭大图查看
    closeViewer:function(){
      this.showViewer = false;
    }
  }
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 148px;
  height: 148px;
  line-height: 148px;
  text-align: center;
}
.avatar {
  width: 148px;
  height: 148px;
  display: block;
}
.el-image-viewer__close{ top: 80px; right: 80px; color: #FFF;}

.fu{ border: 1px solid #F30;}
</style>
